package com.zjw.controller;


import com.zjw.annotation.domain.ResponseResult;
import com.zjw.annotation.domain.entity.User;
import com.zjw.enums.AppHttpCodeEnum;
import com.zjw.exception.SystemException;
import com.zjw.service.AdminLoginService;
import com.zjw.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    private AdminLoginService adminLoginService;


    @PostMapping("/user/login")
    public ResponseResult login(@RequestBody User user) {
//        数据完整性验证
        if (user == null || !StringUtils.hasText(user.getUserName()) || !StringUtils.hasText(user.getPassword()))
            throw new SystemException(AppHttpCodeEnum.LOGIN_INFO_UNCOMPLETED);
        return adminLoginService.login(user);
    }

    @GetMapping("/getInfo")
    public ResponseResult getInfo(){
        return userService.getInfo();
    }

    @GetMapping("/getRouters")
    public ResponseResult getRouters(){
        return userService.getRouters();
    }

    @PostMapping("/user/logout")
    public ResponseResult logout(){
        return adminLoginService.logout();
    }

}
